/*
 * DtmParser.h
 *
 *  Created on: 25.04.2014
 *      Author: gsemmler1
 */

#ifndef DTMPARSER_H_
#define DTMPARSER_H_

#include <iostream>
#include <istream>

#include <string>
#include <vector>

#include <boost/shared_ptr.hpp>

#include <Parsers/IParsingActions.h>

#include <Parsers/GrammarRawStructs.h>
#include <Parsers/SurpacStyleContainer.h>

namespace GST
{
namespace Parsers
{
class DtmParser
{
	enum ParserState
	{
		UNDEFIEND, HEAD, NORMAL_PARSE
	};
	SurpacStyleContainer mStyle;
	const bool mMetaDataParse;
	const std::string mBasePath;
	std::istream* mStrFile;

	int readFile(std::string line, std::istream& dtmFile,
			std::vector<std::string>& lines);
	void parseStrFile(const boost::shared_ptr<IParsingActions>& actions,
			GeometryTypes type, const std::string& strFile);

	void setColor(int id, boost::shared_ptr<IParsingActions> actions);
	bool is_number(const std::string& s);
	void handleNewPart(const boost::shared_ptr<IParsingActions>& actions,
			ParserState state, std::vector<std::string>& parts,
			GeometryTypes type, std::string& strFile, std::stringstream& bodyStream, const std::string& line);
	ParserState checkNewPart(const std::string& line,
			const boost::shared_ptr<IParsingActions>& actions,
			ParserState state, GeometryTypes type, std::string strFile,
			std::vector<std::string>& parts);
	int getInt(std::string s);

public:
	/**
	 * @param styles
	 *       the stylecontainer which should be used
	 * @param metaDataParse
	 *       should parsing be metadataparsing
	 * @param basePath
	 * 		 the basePath to find the str-file, empty if not needed
	 * @param strFile (optional)
	 *       the filestream for the strFile, optinal
	 *
	 *
	 */
	DtmParser(const GST::Parsers::SurpacStyleContainer& styles,
			const bool metadatParse, const std::string& basePath,
			std::istream* strFile = 0) :
			mStyle(styles), mMetaDataParse(metadatParse), mBasePath(basePath), mStrFile(
					strFile)
	{
//		nothing
	}
	/**
	 * Parse a dtm-File from a InputStream
	 * @param dtmFile
	 *        the inputstream
	 * @param actions
	 *        the interface which should be used
	 * @param type
	 *        the geotype which should be parsed
	 */
	void parse(std::istream& dtmFile,
			boost::shared_ptr<IParsingActions> actions, GeometryTypes type);

};
}
}

#endif /* DTMPARSER_H_ */
